package com.tsd.jxc.sale.entity;

import com.alibaba.fastjson.JSON;
import com.tsd.core.utils.HlpUtils;
import com.tsd.core.utils.ListUtil;
import com.tsd.jxc.vo.PrintVo;
import com.tsd.system.entity.SysUserExt;
import io.swagger.annotations.ApiModel;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 销售报价扩展
 *
 * @author Hillpool
 * @date 2022/12/12 11:26:43
 */
@ApiModel(description = "销售报价扩展")
public class JxcSaleQuotationExt extends JxcSaleQuotation implements Serializable {
    /**
     * 暂存
     */
    public static final int STATE_TEMP_SAVE = -1;
    /**
     * 未审核
     */
    public static final int STATE_UN_AUDIT = 0;
    /**
     * 已审核
     */
    public static final int STATE_AUDITED = 1;

    /**
     * 是否生成了销售订单 0-否
     */
    public static final int GEN_SALE_ORDER_NO = 0;
    /**
     * 是否生成了销售订单 2-全部生成
     */
    public static final int GEN_SALE_ORDER_ALL = 2;

    private List<JxcSaleQuotationDetailExt> detail_list;

    private List<Long> id_list;

    private List<String> sid_list;

    private List<String> client_list;

    private String client_name;

    private String client_code;

    private String client_short_name;

    private String client_display;

    private String group_name;

    private String salesman_name;

    private String goods_code;

    private String goods_name;

    private Integer goods_qty;

    private BigDecimal goods_price;

    private BigDecimal goods_amount;

    private String specifications;

    public List<JxcSaleQuotationDetailExt> getDetail_list() {
        return detail_list;
    }

    public void setDetail_list(List<JxcSaleQuotationDetailExt> detail_list) {
        this.detail_list = detail_list;
    }

    public List<Long> getId_list() {
        return id_list;
    }

    public void setId_list(List<Long> id_list) {
        this.id_list = id_list;
    }

    public List<String> getSid_list() {
        return sid_list;
    }

    public void setSid_list(List<String> sid_list) {
        this.sid_list = sid_list;
    }

    public List<String> getClient_list() {
        return client_list;
    }

    public void setClient_list(List<String> client_list) {
        this.client_list = client_list;
    }

    public String getClient_name() {
        return client_name;
    }

    public void setClient_name(String client_name) {
        this.client_name = client_name;
    }

    public String getClient_code() {
        return client_code;
    }

    public void setClient_code(String client_code) {
        this.client_code = client_code;
    }

    public String getClient_short_name() {
        return client_short_name;
    }

    public void setClient_short_name(String client_short_name) {
        this.client_short_name = client_short_name;
    }

    public String getClient_display() {
        return client_display;
    }

    public void setClient_display(String client_display) {
        this.client_display = client_display;
    }

    public String getGroup_name() {
        return group_name;
    }

    public void setGroup_name(String group_name) {
        this.group_name = group_name;
    }

    public String getSalesman_name() {
        return salesman_name;
    }

    public void setSalesman_name(String salesman_name) {
        this.salesman_name = salesman_name;
    }

    public String getGoods_code() {
        return goods_code;
    }

    public void setGoods_code(String goods_code) {
        this.goods_code = goods_code;
    }

    public String getGoods_name() {
        return goods_name;
    }

    public void setGoods_name(String goods_name) {
        this.goods_name = goods_name;
    }

    public Integer getGoods_qty() {
        return goods_qty;
    }

    public void setGoods_qty(Integer goods_qty) {
        this.goods_qty = goods_qty;
    }

    public BigDecimal getGoods_price() {
        return goods_price;
    }

    public void setGoods_price(BigDecimal goods_price) {
        this.goods_price = goods_price;
    }

    public BigDecimal getGoods_amount() {
        return goods_amount;
    }

    public void setGoods_amount(BigDecimal goods_amount) {
        this.goods_amount = goods_amount;
    }

    public String getSpecifications() {
        return specifications;
    }

    public void setSpecifications(String specifications) {
        this.specifications = specifications;
    }

    public String getState_name() {
        if (!HlpUtils.isEmpty(this.getState())) {
            if (this.getState() == STATE_UN_AUDIT) {
                return "待审核";
            } else if (this.getState() == STATE_AUDITED) {
                return "已审核";
            } else if (this.getState() == STATE_TEMP_SAVE) {
                return "暂存";
            }
        }
        return null;
    }

    public String getSpec_name() {
        return null;
    }

    public JxcSaleOrderExt genSaleOrder() {
        JxcSaleOrderExt orderExt = new JxcSaleOrderExt();
        orderExt.setOrder_date(new Date());
        orderExt.setClient_sid(this.getClient_sid());
        orderExt.setQty(this.getQty());
        orderExt.setAmount(this.getAmount());
        orderExt.setPre_freight(this.getPre_freight());
        orderExt.setFree_shipping(this.getFree_shipping());
        orderExt.setDelivery_mode(this.getDelivery_mode());
        List<JxcSaleOrderDetailExt> detailExtList = ListUtil.map(this.getDetail_list(), JxcSaleQuotationDetailExt::genSaleOrderDetail);
        orderExt.setDetail_list(detailExtList);
        return orderExt;
    }

    public PrintVo convert2Print(SysUserExt userExt) {
        PrintVo vo = new PrintVo();
        vo.setCode(this.getCode());
        vo.setCreator_name(this.getCreator_name());
        vo.setCreate_date(this.getCreate_date());
        vo.setAuditor_name(this.getAuditor_name());
        vo.setAudit_date(this.getAudit_date());
        vo.setOrder_date(this.getQuotation_date());
        vo.setClient_display(this.getClient_display());
        vo.setQty(this.getQty());
        vo.setAmount(this.getAmount());
        vo.setPre_freight(this.getPre_freight());
        vo.setFree_shipping(this.getFree_shipping());
        vo.setDelivery_mode(this.getDelivery_mode());
        vo.setSalesman_name(this.getSalesman_name());
        vo.setState(this.getState());
        vo.setNote_info(this.getNote_info());
        List<PrintVo> detailList = ListUtil.map(this.getDetail_list(), JxcSaleQuotationDetailExt::convert2Print);
        vo.setDetail_list(detailList);
        if (userExt != null) {
            vo.setPrint_name(userExt.getName());
        }
        vo.setPrint_datetime(new Date());
        return vo;
    }
}
